<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>短信营销1-创建3</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/public.css" />
    <link rel="stylesheet" type="text/css"
	href="<%=path%>/css/marketing/style_list.css" />
	<link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/mobile_coupon_public.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/marketing/mobile_coupon_style.css" />
	
    <link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link href="<%=path%>/hplus/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
    <link href="<%=path%>/css/marketing/s_style.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="<%=path%>/hplus/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
   
    <style> 
        .radio label{
            padding-left: 0;
        }

        .date{
            margin: -8px 20px 0 0;
        }

        .clockpicker{
            margin-top: -8px;
        }

        .i-checks label{
            float: left;
            margin-right: 10px;
        }

        .col-sm-offset-1{
            margin-top: 20px;
        }

        .tishi{
            margin-top: 7px;
            
        }

        .alert{
            position:absolute;
            top: -15px;
            left: 8%;
            display:none;
        }
        .text-center{
            width:50%;
            margin: 10px 0 20px;
        }
        
        .bbb{
        	width:14%;
        	float:left;
        }
         .col-md-8{
        	border-right:1px solid #ddd;
        }
    </style>
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content">
	    <div class="row ibox-content" style="width:100%">
	      <div class="col-md-12"  style="width:100%">
	        <div class="col-md-8">
		        <form id="createForm" method="get" class="form-horizontal">
	                <div class="form-group">
	                   <label class="col-sm-2 control-label">惠券名称</label>
	                    <div class="col-sm-7">
	                        <div class="radio i-checks col-sm-3">
	                            <label class="operation">
	                                <input type="radio" checked="" id="yes" name="type" value="0"> <i></i>优惠券</label>
	                        </div>
	                        <div class="radio i-checks col-sm-3">
	                            <label class="operation">
	                                <input type="radio" id="no" name="type" value="1"> <i></i> 物品券</label>
	                        </div>
	                        <div class="col-sm-6">
                                    <input type="text" id="name" name="name" class="form-control" maxlength="20" onblur="checkLength(this)" oninput="reloadRight()">
                            </div>
	                    </div>
	                    
	                </div>
	
	                <div class="form-group priceGroup">
	                   <label class="col-sm-2 control-label">金额</label>
	                    <div class="col-sm-10">
	                       <div class="col-sm-12" style="margin-left:-14px">
		                        <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio" checked=""  name="faceValue" value="5"> <i></i>5元</label>
		                        </div>
		                        <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio" id="no" name="faceValue" value="10"> <i></i>10元</label>
		                        </div>
		                         <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio"   name="faceValue" value="20"> <i></i>20元</label>
		                        </div>
		                        <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio" id="no" name="faceValue" value="50"> <i></i>50元</label>
		                        </div>
		                         <div class="bbb radio i-checks">
		                            <label class="operation priceLab">
		                                <input type="radio"   name="faceValue" value="100"> <i></i>100元</label>
		                        </div>
	                       </div>
	                       <div class="col-sm-12" style="margin-left:-14px;margin-top:10px"">
	                            <div class="radio i-checks" style="width:40%;float:left;">
		                            <label class="operation">
		                                <input type="radio"   name="faceValue" value="-1" id="defined_value_radio"> <i></i>自定义</label>
		                                <div class="col-sm-6">
				                             <input type="text" class="form-control" id="defined_value" disabled="disabled" style="margin-top:-8px;margin-left:-10px;"  onkeyup="num(this)" maxlength="5">
			                            </div>
		                        </div>
	                       </div> 
	                        
	                    </div>
	                </div>
	
	               <div class="form-group">
	                    <label class="col-sm-2 control-label">有效日期</label>
	                    <div class="col-sm-7">
	                        <div class="form-group col-sm-4">
		                        <select id="validity_period_type" class="form-control" name="account" >
			                        <option value="0">固定有效期</option>
			                        <option value="1">相对有效期</option>
			                    </select>
		                    </div>
		                     <div class="form-group col-sm-8" id="choseExpireTime">
			                    <div class="input-daterange input-group" id="datepicker" style="padding-left:15px">
			                        <input id="start_time" type="text" class="input-sm form-control" name="start" value=""  onchange="startTimeChange()"/>
			                        <span class="input-group-addon">至</span>
			                        <input id="end_time" type="text" class="input-sm form-control" name="end" value=""  onchange="endTimeChange()"/>
			                    </div>
			                </div>  
			                 <div hidden="" class="col-sm-5" id="choseAfterDay">
			                    <div class="col-sm-10" >
	                               <input type="text" id="afterDay" class="form-control" onkeypress="keyPress()" maxlength="2">
	                            </div>
	                            <span class="col-sm-2 text-left" style="margin-left:-10px;margin-top:8px">天</span>
			                </div>  
	                    </div>
	                </div>
	
	               <div class="form-group">
	                    <label class="col-sm-2 control-label">使用条件</label>
	                    <div class="col-sm-8">
	                        <div class="col-sm-3" style="margin-left:-14px">
                               <label class="checkbox-inline i-checks" ><input id="limit_price_check" type="checkbox" value="option1">订单满</label>
                            </div>
	                        <div class="col-sm-3" style="margin-left:-50px">
                               <input type="text" id="limit_price" disabled="disabled" class="form-control"   onkeyup="num(this)" maxlength="7">
                            </div>
                            <span class="col-sm-2 text-left" style="margin-left:-10px;margin-top:8px">元使用</span>
	                    </div>
	               </div>
	               
	               <div class="form-group">
	                    <label class="col-sm-2 control-label">使用时段</label>
	                    <div class="col-sm-10">
	                    
	                           <div class="col-sm-12" style="margin-left:-14px">
		                           <label class="checkbox-inline i-checks choseWeekLable"><input id="no_set" checked="checked" type="checkbox" value="option1">不设</label>
	                              	                              
	                           </div>
	                           <div class="col-sm-12 no_set" style="margin-left:-14px" hidden="">
	                              <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week1" class="choseWeek" type="checkbox" value="周一">周一</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week2" class="choseWeek" type="checkbox" value="周二">周二</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week3" class="choseWeek" type="checkbox" value="周三">周三</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week4" class="choseWeek" type="checkbox" value="周四">周四</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week5" class="choseWeek" type="checkbox" value="周五">周五</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week6" class="choseWeek" type="checkbox" value="周六">周六</label>
	                               <label class="checkbox-inline i-checks choseWeekLable"><input id="chose_week7" class="choseWeek" type="checkbox" value="周日">周日</label>
	                           </div>
	                           <div class="col-sm-7 no_set" style="margin-left:-22px;margin-top:8px"  hidden="">
	                               <div class="col-sm-4" style="margin-left:-20px;float:left;">
	                                 <label class="checkbox-inline i-checks" style="float:right"><input id="periodTimeHourFlag" disabled="disabled" type="checkbox" value="option1">时间</label>
	                               </div>
		                           <div class="input-group clockpicker col-sm-3" style="float:left;margin-top:1px" data-autoclose="true">
		                                <input id="start_hour" disabled="disabled"  type="text" class="form-control periodTimeHour" value="09:00" onchange="startTimeHourChange()">
		                           </div>
		                           <div class="col-sm-1" style="margin-top:8px">
		                                <span class="text-center" >至</span>
		                           </div>
		                            
		                            <div class="input-group clockpicker col-sm-3" style="float:left;margin-top:1px" data-autoclose="true">
		                                <input id="end_hour"  disabled="disabled" type="text" class="form-control periodTimeHour" value="22:00" onchange="endTimeHourChange()">
		                           </div>
	                           </div>
	                    </div>
	               </div>
	               
	               <div class="form-group">
	                   <label class="col-sm-2 control-label">使用规则</label>
	                    <div class="col-sm-10" style="margin-left:-14px">
	                       <div class="col-sm-12">
		                        <div class="radio i-checks col-sm-3">
		                            <label class="operation">
		                                <input type="radio" checked=""  name="useRule" value="5"> <i></i>单张使用</label>
		                        </div>
		                        <div class="radio i-checks  col-sm-3">
		                            <label class="operation">
		                                <input type="radio" id="no" name="useRule" value="10"> <i></i>多张使用</label>
		                        </div>
	                       </div>
	                       
	                    </div>
	                </div>
	                <div class="form-group">
	                   <label class="col-sm-2 control-label" >使用说明</label>
	                    <div class="col-sm-6">                      
	                        <textarea  id="useDesc"  class="form-control" required="" aria-required="true" style="height:150px;"></textarea>                       
	                    </div>
	                    
	                </div>
	                <%-- <div class="form-group">
	                    <label class="col-sm-2 control-label">选择门店</label>
	                       <div class="col-sm-2">
	                          <input id="choseStoreIds" type="text" value="选择门店" readonly="readonly" class="form-control" data-toggle="modal" href="<%=path%>/api/bm/ui/store" data-target="#store_modal">
	                       </div>
	                </div> --%>
	                         
	            </form>
	        </div>
	        <div class="col-md-4" hidden="">
	            <h3 style="text-align:center;">优惠券预览</h3>
	            <div class="container" style="width:355px;margin:0 auto;">
                    <ul class="surrent" style="width:355px;height:143px;">
			            <li id="right_coupon" class="coupon_yellow">
		                    <div class="left">
		                    	<b>￥</b>
		                        <span id="right_price">5</span>
		                    </div>
		                    <div class="right">
		                        <i title="" class="coupon_name_right">优惠券</i>
		                        <i class="limit_condition">满0元使用</i>
		                        <em class="right_hour">2017-12-27-2018-1-27</em>
		                    </div>
		                    <p class="right_time" hidden="">使用时间:周一、周三、周五 12:00-14:00</p>
		                </li>
		                
		                 <li id="right_voucher" class="coupon_yellow s_coupon" hidden="">
		                    <h2 title="" class="coupon_name_right">物品券</h2>
		                    <h3 class="limit_condition">满0元使用</h3>
		                    <em class="right_hour">2017-12-27-2018-1-27</em>
		                    <p class="right_time"  hidden="">使用时间:周一、周三、周五 12:00-14:00</p>
		                </li>
		             </ul>
		          </div>      
	        </div>
	      </div>  
	      <div class="col-md-12">
	      <div class="col-sm-3"></div>
	         <div class="col-sm-4 text-center">
	           <div class="col-sm-3"></div>
	           <button id="btn_cancel" class="btn btn-outline btn-primary col-sm-2" onclick="javascript:history.back();" type="button">取消</button>
	           <div class="col-sm-2"></div>
	           <button id="btn_save" class="btn btn-primary col-sm-2" type="button" onclick="javascript:save();">确认</button>
	           <div class="col-sm-3"></div>
	         </div>
	         <div class="col-sm-5"></div>
	      </div>
	        
	    </div>    
    </div>
    
    <div class="modal inmodal fade" id="store_modal" tabindex="-1" role="dialog"  aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
            </div>
        </div>
    </div>
    
    <script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="<%=path%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jsKnob/jquery.knob.js"></script>
    <script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
    <script src="<%=path%>/hplus/js/plugins/switchery/switchery.js"></script>
    <script src="<%=path%>/hplus/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
    <script src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
    <script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
    
    <script src="<%=path%>/hplus/js/demo/form-advanced-demo.min.js"></script>
	<script src="<%=path%>/hplus/js/plugins/suggest/bootstrap-suggest.min.js"></script>
    <script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
	<script type="text/javascript" src="<%=path%>/js/marketing/lengthlimit.js"></script>
	   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>

    <script type="text/javascript">
	    $('#limit_price_check').on('ifChecked', function(event){
		   	limitPriceFlag=true;
		   	$("#limit_price").removeAttr("disabled");
		   	$('.limit_condition').show();
	    });
	    
	    $('#limit_price_check').on('ifUnchecked', function(event){
		   	limitPriceFlag=false;
		   	$("#limit_price").attr("disabled","disabled");
			$('.limit_condition').hide();
	    });
    
	    $('#no_set').on('ifChecked', function(event){
	    	$(".choseWeek").attr("disabled","disabled");
	    	$(".choseWeek").parent().removeClass("checked");
	    	$("#periodTimeHourFlag").attr("disabled","disabled");
	    	$("#periodTimeHourFlag").parent().removeClass("checked");
	    	$(".periodTimeHour").attr("disabled","disabled");
	    	useTimeType=0;
	    	$('.no_set').hide();
	    	$(".right_time").hide();
	    });
	    
	    $('#no_set').on('ifUnchecked', function(event){
	    	$(".choseWeek").removeAttr("disabled");
	    	$("#periodTimeHourFlag").removeAttr("disabled");
	    	$("#periodTimeHourFlag").parent().removeClass("disabled");
	    	$('.no_set').show();
	    	$(".right_time").show();
	    	useTimeType=1;
	    });
	    
	    $('#periodTimeHourFlag').on('ifChecked', function(event){
	    	periodTimeHourFlag=true;
	    	$(".periodTimeHour").removeAttr("disabled");
	    	var startHour=$('#start_hour').val();
			var endHour=$('#end_hour').val();
			periodTimeHour=startHour+"-"+endHour;
	    	reload();
	    });
	    
	    $('#periodTimeHourFlag').on('ifUnchecked', function(event){
	    	periodTimeHourFlag=false;
	    	$(".periodTimeHour").attr("disabled","disabled");
	    	periodTimeHour="";
	    	reload();
	    });
	    
	    $("#validity_period_type").change(function(){  
	    	validityPeriodType=$(this).children('option:selected').val();
	    	if(validityPeriodType==0){
	    		$("#choseAfterDay").hide();
	    		$("#choseExpireTime").show();
	    	}else if(validityPeriodType==1){
	    		$("#choseExpireTime").hide();
	    		$("#choseAfterDay").show();
	    	}
	    	reloadRight();
	    }) 
	     $('#defined_value_radio').on('ifChecked', function(event){
	    	$("#defined_value").removeAttr("disabled");
	    	definedValueFlag=true;
	    });
	    
	    $('#defined_value_radio').on('ifUnchecked', function(event){
	    	$("#defined_value").attr("disabled","disabled");
	    	definedValueFlag=false;
	    });
	    
	    $(document).on('ifChecked', '#yes', function() {
	    	newCouponModel=true;
	    	$('.priceGroup').show();
	    	$('#right_coupon').show();
	    	$('#right_voucher').hide();
	    });
	    
	    $(document).on('ifUnchecked', '#yes', function() {
	    	newCouponModel=false;
	    	$('.priceGroup').hide();
	    	$('#right_coupon').hide();
	    	$('#right_voucher').show();
	    	
	    });
	    
	    $('.priceLab').on('ifChecked', function(event){
        	reloadRight();
        });
        $('.priceLab').on('ifUnchecked', function(event){
        	reloadRight();
        });
        
        $('.choseWeekLable').on('ifChecked', function(event){
        	$(this).children().addClass("checked");
        	reload();
        });
        $('.choseWeekLable').on('ifUnchecked', function(event){
        	$(this).children().removeClass("checked");
        	reload();
        });
        
        
	    function reload(){
	    	periodTimeWeek="";
	    	$(".choseWeekLable .checked").children()
			   .each(
					function(i, d) {
						if(StringEmpty(this.id)){
							periodTimeWeek = periodTimeWeek + "," +this.value; 
						}
			});
	    	periodTimeWeek=periodTimeWeek.replace(",","");
	    	periodTimeWeek=handlePeriodTimeWeek(periodTimeWeek);
	    	if(periodTimeHourFlag){
  			    var startHour=$('#start_hour').val();
  			    var endHour=$('#end_hour').val();
  			    periodTimeHour=startHour+"-"+endHour;
	    		$('.right_time').html("使用时间:"+periodTimeWeek+" "+periodTimeHour);
	    	}else{
	    		$('.right_time').html("使用时间:"+periodTimeWeek);
	    	}
	    	
	    	
	    }
        function reloadRight(){
        	
        	if(StringEmpty($('#name').val())){
        		$('.coupon_name_right').html($('#name').val());
        		$('.coupon_name_right').attr("title",$('#name').val());
        	}
        	
        	if(StringEmpty($('#limit_price').val())){
        		$('.limit_condition').html("满"+$('#limit_price').val()+"元使用");
        	}else{
        		$('.limit_condition').html("满0元使用");
        	}
        	
        	if(StringEmpty($("input[name='faceValue']:checked").val())){
        		var value=$("input[name='faceValue']:checked").val();
        		if(value==-1){
        			$('#right_price').html(0);
        		}else{
        			$('#right_price').html(value);
        		}
        		
        	}
        	
        	if(StringEmpty($('#defined_value').val())){
        		$('#right_price').html($('#defined_value').val());
        	}
         	if(validityPeriodType==0){
         		 var startTime=$('#start_time').val();
  			     var endTime=$('#end_time').val();
         		 if(CompareDate(startTime,endTime)){
        			 $('#end_time').val(startTime);
        			 $('.right_hour').html(startTime+'-'+startTime);
     			  }else{
     				 $('.right_hour').html(startTime+'-'+endTime);
     			  }
        		
        	}else{
        		$('.right_hour').html('有效期已发出为准');
        	}
        }
        
        function startTimeChange(){
       	 var startTime=$('#start_time').val();
			 var endTime=$('#end_time').val();
			   
   		 if(CompareDate(startTime,endTime)){
   			 $('#end_time').val(startTime);
   			 $('.right_hour').html(startTime+'-'+startTime);
			  }else{
				 $('.right_hour').html(startTime+'-'+endTime);
			  }
       }
       function endTimeChange(){
      	     var startTime=$('#start_time').val();
			 var endTime=$('#end_time').val();
			   
	   		 if(CompareDate(startTime,endTime)){
	   			 $('#start_time').val(endTime);
	   			 $('.right_hour').html(startTime+'-'+startTime);
			 }else{
				 $('.right_hour').html(startTime+'-'+endTime);
			 }
      }
       
       function startTimeHourChange(){
    	   if(periodTimeHourFlag){
			    var startHour=$('#start_hour').val();
			    var endHour=$('#end_hour').val();
			    
			    var startHourTemp=startHour.split(":")[0];
 			    var endHourTemp=endHour.split(":")[0];
 			    
 			    if(parseInt(startHourTemp)>parseInt(endHourTemp)){
			    	endHour=startHour;
	 			}
 			   $('#start_hour').val(startHour);
  			  $('#end_hour').val(endHour);
			    periodTimeHour=startHour+"-"+endHour;
	    		$('.right_time').html("使用时间:"+periodTimeWeek+" "+periodTimeHour);
	    	}else{
	    		$('.right_time').html("使用时间:"+periodTimeWeek);
	    	}
       }
       
       function endTimeHourChange(){
 			    var startHour=$('#start_hour').val();
 			    var endHour=$('#end_hour').val();
 			    var startHourTemp=startHour.split(":")[0];
 			    var endHourTemp=endHour.split(":")[0];
 			   
 			    if(parseInt(startHourTemp)>parseInt(endHourTemp)){
 				  startHour=endHour;
 			    }
 			   
 			   $('#start_hour').val(startHour);
 			  $('#end_hour').val(endHour);
 			    periodTimeHour=startHour+"-"+endHour;
	    		$('.right_time').html("使用时间:"+periodTimeWeek+" "+periodTimeHour);
	    	
       }
       
    </script>


	<script type="text/javascript">
       var access_token=$.cookie('access_token');
   	   var cid=$.cookie('cid');
   	   var uid=$.cookie('uid');
	   var name="";
	   var type="";
	   var faceValue="";
	   var validityPeriodType="0";
	   var limitPrice="";
	   var useTimeType="";
	   var periodTimeWeek="";
	   var periodTimeHour="";
	   var periodTimeHourFlag=false;
   	   var limitPriceFlag=false;
   	   var definedValueFlag=false;
   	   var start_time="";
   	   var end_time="";
   	   var afterDay="";
       var store_ids=new Array();
       var store_names=new Array();
       var useRule=0;
       var storeIds="";
       var useDesc="";
   	   $(function(){
   		    init();
	   		var myDate = new Date();
	    	//获取当前年
	    	var year=myDate.getFullYear();
	    	//获取当前月
	    	var month=myDate.getMonth()+1;
	    	var lastMoth=myDate.getMonth()+2;
	    	//获取当前日
	    	var day=myDate.getDate(); 
	    	if(day<10)
	        	day="0"+day;
	    	if(month<10)
	    		month="0"+month;
	    	$("#start_time").val(year+"-"+month+"-"+day);
	        $('#start_time').datepicker({  
	            todayBtn : "linked",  
	            autoclose : true,  
	            todayHighlight : true, 
	            startDate : new Date()  
	        }).on('changeDate',function(e){  
	        });
	        if(lastMoth>12){
	        	year=year+1;
	        	lastMoth=lastMoth-12;
	        }
	        if(lastMoth<10)
	        	lastMoth="0"+lastMoth;
	        
	        $("#end_time").val(year+"-"+lastMoth+"-"+day);
	        $('#end_time').datepicker({  
	            todayBtn : "linked",  
	            autoclose : true,  
	            todayHighlight : true, 
	            startDate : new Date()  
	        }).on('changeDate',function(e){  
	        	
	        });
	        reloadRight();
   	   })
   	   
   	   
   	   
   	   function init(){
   		  $('.choseWeek').attr("disabled","disabled");
   		  $('.limit_condition').hide();
		}
	
   	   
   	    function save(){
   	      name=$.trim($("#name").val());
   		  type= $("input[name='type']:checked").val();
   		  var useDescVal=$("#useDesc").val();
   		  //处理使用详细说明
   		  if(StringEmpty(useDescVal)){
   			var useDescTemp=useDescVal.split("\n");
   		    for(var i in useDescTemp){
   			    if(StringEmpty(useDescTemp[i])){
   				  useDesc=useDesc+"<li>"+useDescTemp[i]+"</li>";
   			    }
   			}
   		  }
   		  if(type==0){
   			faceValue=$("input[name='faceValue']:checked").val();
   		  }
   		  useRule=$("input[name='useRule']:checked").val();
   		  if(faceValue==-1){
   			 faceValue=$('#defined_value').val();
   		  }
   		  
   		  if(limitPriceFlag){
   			limitPrice=$('#limit_price').val();
   			limitPrice=Number(limitPrice)*100;
   			limitPrice=parseInt(limitPrice);
   		  }
  		  
  		  if(periodTimeHourFlag){
  			  var startHour=$('#start_hour').val();
  			  var endHour=$('#end_hour').val();
  			  periodTimeHour=startHour+"-"+endHour;
  		  }
  		  
  		  //判断是相对日期还是固定日期
  		  if($("#validity_period_type").val()==0){
  			  start_time=$('#start_time').val();
     		  end_time=$('#end_time').val();
  		  }else if($("#validity_period_type").val()==1){
  			  afterDay=$("#afterDay").val();
  			  if($.trim(afterDay) == ""){
  				  alert("请填写相对有效期");
  				  return ;
  			  }
  		  }
  		  if(!StringEmpty(name)){
  			promptDialog("请输入名称");
  			return ;
  		  }
  		  if(type==0){
  			if(!StringEmpty(faceValue)||faceValue==-1){
  	  			promptDialog("请设置金额");
  	  			return ;
  	  		}
  			faceValue=Number(faceValue)*100;
  			faceValue=parseInt(faceValue);
  		  }
  		  if($("#limit_price_check").get(0).checked){
			if($.trim($("#limit_price").val()) == ""){
				promptDialog("请填写使用条件");
				return ;
			}
  		  }
  		  if(!$("#no_set").is(':checked')){
  				if(periodTimeWeek=="" && periodTimeHour==""){
  					alert("请填写使用时段");
  					return ;
  				}
  		  }
  		  
  		  storeIds=store_ids.join(",");
  		  $.post("<%=path%>/couponDefinedTemplate/ajaxCountCouponTemplateNum",{name:name},function(data){
				if(data.status == "200"){
					if(data.data == 0){
						create();
					}else{
						promptDialog("名称重复");
					}
				}
  		  },"json");
   	    } 
   	   
        function create(){
        	var url="<%=path%>/couponDefinedTemplate/ajaxCreateDefinedTemplate";
        	var obj = {
      				"name":name,
      				"type":type,
      				"faceValue":faceValue,
      				"validityPeriodType":validityPeriodType,
      				"limitPrice":limitPrice,
      				"useTimeType":useTimeType,
      				"periodTimeWeek":periodTimeWeek,
      				"periodTimeHour":periodTimeHour,
      				"startTimeStr":start_time,
      				"endTimeStr":end_time,
      				"afterDay":afterDay,
      				"storeIds":storeIds,
      				"useRule":useRule,
				    "useDescribe":useDesc,
      			};
          	$.post(url, obj, function(data) {
  				if (data.status == "200") {
  					window.location.href='<%=path%>/view/coupon/main';
  				} else if(data.message=="20028"){
  					loginDialog();
  				}else {
  					errorDialog("创建失败",data.message);
  				}
  			});
        }
        function colseModal(){
        	$('#store_modal').modal('hide');
        }
        
        function determineStore(){
        	$('#store_modal').modal('hide');
        	if(store_ids!=null&&StringEmpty(store_ids)){
        		$("#choseStoreIds").val("已选择");
        	}else{
        		$("#choseStoreIds").val("选择优惠券");
        	}
        	
        	
        } 
		 
        function num(obj){
        	obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
        	obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
        	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
        	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        	obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
        	reloadRight();
        }
        
        function handlePeriodTimeWeek(periodTimeWeek){
        	var temp=periodTimeWeek.split(",");
        	if(temp.length==7){
        		return "周一至周日";
        	}else if(temp.length==5){
            	var workDayFlag=true;
        		for(var i in temp){
        			if(temp[i]=="周日"||temp[i]=="周六"){
        				workDayFlag=false;
        				break;
        			}
        		}
        		if(workDayFlag){
        			return "周一至周五";
        		}else{
        			return periodTimeWeek;
        		}
        	}else{
        		return periodTimeWeek;
        	}
        }
        function CompareDate(d1,d2)
        {
          return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
        }
	</script>

    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
</body>
</html>
